package com.mavenq.fly.business.controller;

import com.mavenq.fly.annotation.Log;
import com.mavenq.fly.business.entity.Role;
import com.mavenq.fly.business.entity.User;
import com.mavenq.fly.business.service.RoleService;
import com.mavenq.fly.commons.resp.ResponseBuilder;
import com.mavenq.fly.commons.resp.ResponseObj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author cpf
 * @since 2025-05-09
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @RequestMapping("add")
    @Log(title = "创建角色", operation = "褚鹏飞")
    public ResponseObj<Role> add(@RequestBody Role role){
        boolean saved = roleService.save(role);
        if(saved){
            return ResponseBuilder.buildSuccess(role);
        }
        return ResponseBuilder.buildFailed();
    }

    @RequestMapping("update")
    @Log(title = "更新角色", operation = "褚鹏飞")
    public ResponseObj<Role> update(@RequestBody Role role){
        boolean updateById = roleService.updateById(role);
        if(updateById){
            return ResponseBuilder.buildSuccess(role);
        }
        return ResponseBuilder.buildFailed();
    }
}
